# 20.py
# 迭代器2


class Person:

  def __init__(self):
    self.result = 1

  def __getitem__(self,item):
    print('getitem')
    self.result += 1
    if self.result >= 6:
      raise StopIteration('停止遍历')
    return self.result

  def __iter__(self):
    print('iter')
    return self

  def __next__(self):
    print('next')
    self.result += 1
    if self.result >= 6:
      raise StopIteration('停止便利')

    return self.result


  pass

p = Person()

for i in p:
  print(i)

# print(next(p))
